<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/client/backgroundManagement/commons/global.jsp" %>

<script>
	var path = "/sddc/client/";
	console.log(path)
	var dojoConfig = {
		serverIP : location.host,
		gfxRenderer : "svg,canvas,vml",
		packages : [ {
			name : 'app',
			location : path + 'app'
		}, {
			name : 'gistech',
			location : path + 'gistech'
		} ]
	};
</script>

<script type="text/javascript"
	src="/arcgis_js_api/v313/library/3.13/init.js"></script>
	
<script type="text/javascript">
require([ "dojo/parser","dojo/_base/lang", "dojo/on",  "gistech/util/ajaxUtil", "dijit/dijit", "esri/tasks/QueryTask","esri/tasks/query","dojo/ready" ], function(
		Parser,lang,on,ajaxUtil, dijit,QueryTask,query, ready) {
	    var resultLayer ='' ; 
        $('#roleEditForm').form({
            url : '${path }/serverController/edit',
            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                
/*                 if(isValid){
                	var now = dojo.byId('dynamicsUrl').value;
                	var old = dojo.byId('olddynamicsUrl').value
                	
                	if(now != old){
                		isValid = checkFlag(isValid);
                	}
                } */
                return isValid;
            },
            success : function(result) {
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                    parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
                    
/*                     if(resultLayer!=''){
                    	var serverInfoId = dojo.byId('serverInfoId').value
 						var params = "serverInfoId="+serverInfoId+"&layerInfo="+resultLayer;
	                	ajaxUtil.request("${path }/layerInfoController/edit",
	                			params,lang.hitch(this,function(result){
	           	    			 var Store = eval(result.result);
	        	    			 if(Store!=null && Store.length>0){
	        	    				 ioc.map.userOrganization = Store;
	        	    			 }else{
	        	    				 ioc.map.userOrganization = [];
	        	    			 }
	        	    			 this.getOrganizationList();
	        	    	}));
                    	
                    } */
                    
                    parent.$.modalDialog.handler.dialog('close');
                } else {
                    parent.$.messager.alert('错误', result.msg, 'error');
                }
            }
        });
        

        $("#description").val('${entity.description}');
        $("#status").val('${entity.status}');
     
    
/* 	function checkFlag(isValid){
		 
	  if(isValid){
			isValid=false;
            //验证动态URL
            var dynamicUrl =   dojo.byId('dynamicsUrl').value; 
			var queryTask=new QueryTask(dynamicUrl);
			    query = new esri.tasks.Query();
			try{
       			 queryTask.execute(query, function(resp){
       				 
	       			    if(resp.layers.length !=0 ){ 
	       			      isValid=true;
	       			         resultLayer ='' ; 
		       			      for(var i=0;i<resp.layers.length;i++){ 
		       			    	  //debugger;
		       			       resultLayer += (resp.layers[i].name+'('+resp.layers[i].id+')|')
		       			      }
	       			    }else{
	       			    	progressClose();
	       			     alert('服务下无图层,请确认动态服务URL无误');
	       			     
	       			    }
	       			 return isValid;
	       		 })
			}catch(e){
				 progressClose();
				 alert('读取服务出错,请确认动态服务URL无误');
				 return isValid;
			}
		}
	 } */
    
    });
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false" title="" style="overflow: hidden;padding: 3px;">
        <form id="roleEditForm" method="post">
            <table class="grid">
 
 	            <tr>
                    <td>名称</td>
                    <td>
	                    <input name="id" type="hidden"  value="${entity.id}">
	                  
	                    <input name="name" type="text" placeholder="请输入服务名称" class="easyui-validatebox span2" data-options="required:true" value="${entity.serverName }">
                    </td>
                </tr>
 
                <tr>
                    <td>状态</td>
                    <td >
                        <select id="status" name="status" class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto'">
                                    <option value="1">可用</option>
                                    <option value="2">停用</option>
                        </select>
                    </td>
                </tr>
                
                <tr>
                    <td>动态服务URL</td>
                    <td>
                    <input name="dynamicsUrl" type="text" readonly="readonly" id = "dynamicsUrl" placeholder="请输入URL" class="easyui-validatebox span2" data-options="required:true" style="width:350px" value="${entity.dynamicsUrl}">
                    <input name="olddynamicsUrl" type="hidden" id = "olddynamicsUrl"  placeholder="请输入URL" class="easyui-validatebox span2" data-options="required:true" style="width:350px" value="${entity.dynamicsUrl}">
                    </td>
                </tr>
                
                <tr>
                    <td>要素服务URL</td>
                    <td><input name="featureUrl" readonly="readonly" type="text" placeholder="请输入URL" class="easyui-validatebox span2" data-options="required:true" style="width:350px" value="${entity.featureUrl}"></td>
                </tr>
                
                 <tr>
                    <td>备注</td>
                    <td colspan="5"><textarea id="description" name="description" rows="" cols="" style="width: 350px;height: 50px"></textarea></td>
                </tr>
            </table>
        </form>
    </div>
</div>